package com.ttbj.util;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RequestUtils {
	private static Logger log = LoggerFactory.getLogger(RequestUtils.class);

	/**
	 * 获取回调地址
	 * @param request
	 *            请求对象
	 * @return 回调地址
	 */
	public static String getRequestPath(HttpServletRequest request) {
		String serverName = request.getServerName();
		Integer serverPort = request.getServerPort();
		String contextPath = request.getContextPath();
		String portExt = "";
		if(serverPort != 80){
			 portExt = ":"+serverPort+contextPath;
		} 
		log.info("回调地址是====》"+"http://" + serverName + portExt + "/");
		return "http://" + serverName + portExt + "/";
	}
	
	
	/**
	 * 获取根路径
	 *
	 * @return
	 */
	public  String getXmlPath() {
		String classpath = this.getClass().getResource("/").getPath();
		String webappRoot = classpath.replaceAll("WEB-INF/classes/", "");
		return webappRoot;
	}
	
	

}
